﻿<Window x:Class="FileRenamer.RenamerView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:FileRenamer"
        Title="Name Changer WPF" MinHeight="300" MinWidth="300" Height="500" Width="600">

    <Window.Resources>
        <Style x:Key="CollapsedOnAppendPrependAndSequence">
            <Setter Property="FrameworkElement.Visibility" Value="Visible" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=ChangerComboBox, Path=SelectedItem}" Value="Append">
                    <Setter Property="FrameworkElement.Visibility" Value="Collapsed"></Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=ChangerComboBox, Path=SelectedItem}" Value="Prepend">
                    <Setter Property="FrameworkElement.Visibility" Value="Collapsed"></Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=ChangerComboBox, Path=SelectedItem}" Value="Sequence">
                    <Setter Property="FrameworkElement.Visibility" Value="Collapsed"></Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="CollapsedOnSequence">
            <Setter Property="FrameworkElement.Visibility" Value="Visible" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=ChangerComboBox, Path=SelectedItem}" Value="Sequence">
                    <Setter Property="FrameworkElement.Visibility" Value="Collapsed"></Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="VisibleOnSequence">
            <Setter Property="FrameworkElement.Visibility" Value="Collapsed" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=ChangerComboBox, Path=SelectedItem}" Value="Sequence">
                    <Setter Property="FrameworkElement.Visibility" Value="Visible"></Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid Grid.Row="0" Grid.ColumnSpan="2" Margin="0,0,0,10">
            <StackPanel Orientation="Horizontal">
                <Button Content="Add" Margin="0,0,10,0" Padding="10,0,10,0" Command="{Binding AddFilesCommand}" />
                <Button Content="Remove" Margin="0,0,10,0" Padding="10,0,10,0" Command="{Binding RemoveFileCommand}" 
                        IsEnabled="{Binding ElementName=MyDataGrid, Path=SelectedItems.Count}" />
                <Button Content="Clear" Padding="10,0,10,0" Command="{Binding ClearFilesCommand}" 
                        IsEnabled="{Binding Path=Files.Count}" />
            </StackPanel>
            <Button Content="Rename" Padding="10,0,10,0" HorizontalAlignment="Right" Command="{Binding RenameFilesCommand}"
                    IsEnabled="{Binding Path=Files.Count}" />
        </Grid>

        <Grid Grid.Row="1" Grid.ColumnSpan="2" Margin="0,0,0,5">
            <StackPanel Grid.Row="1" Grid.Column="0">

                <ComboBox Name="ChangerComboBox" Margin="0,0,0,5" 
                          IsEnabled="{Binding Path=Files.Count}"
                          ItemsSource="{Binding ChangerTypes}"
                          SelectedItem="{Binding CurrentChangerType}">
                </ComboBox>

                <DockPanel Width="Auto" Style="{StaticResource CollapsedOnAppendPrependAndSequence}">
                    <TextBlock Text="Replace Text:" Margin="0,0,10,5" Width="90" />
                    <TextBox Margin="0,0,0,5" 
                             IsEnabled="{Binding Path=Files.Count}"
                             Text="{Binding OriginalText, UpdateSourceTrigger=PropertyChanged}" />
                </DockPanel>

                <DockPanel Width="Auto" Style="{StaticResource CollapsedOnSequence}">
                    <TextBlock Text="With Text:" Margin="0,0,10,5" Width="90" />
                    <TextBox Margin="0,0,0,5" 
                             IsEnabled="{Binding Path=Files.Count}" 
                             Text="{Binding NewText, UpdateSourceTrigger=PropertyChanged}" />
                </DockPanel>

                <StackPanel Name="SequenceOptionsPanel" Style="{StaticResource VisibleOnSequence}">
                    <DockPanel Width="Auto">
                        <TextBlock Text="Starting Digit:" Margin="0,0,10,5" Width="90" />
                        <TextBox Margin="0,0,0,5" Text="{Binding SeqStartingDigit, UpdateSourceTrigger=PropertyChanged}" />
                    </DockPanel>
                    <DockPanel Width="Auto">
                        <TextBlock Text="Leading Zeros:" Margin="0,0,10,5" Width="90" />
                        <local:NumericControl Margin="0,0,0,5" CurrentNum="{Binding Path=SeqLeadingZeros, UpdateSourceTrigger=PropertyChanged}" />
                    </DockPanel>
                </StackPanel>

                <StackPanel Orientation="Horizontal">
                    <CheckBox Content="Ignore Case" Margin="0,0,20,5" 
                              IsEnabled="{Binding Path=Files.Count}" 
                              IsChecked="{Binding IgnoreCase, UpdateSourceTrigger=PropertyChanged}"
                               Style="{StaticResource CollapsedOnAppendPrependAndSequence}" />
                    <CheckBox Content="Ignore Extension" Margin="0,0,0,5" 
                              IsEnabled="{Binding Path=Files.Count}" 
                              IsChecked="{Binding IgnoreExtension, UpdateSourceTrigger=PropertyChanged}">
                        <CheckBox.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=ChangerComboBox, Path=SelectedItem}" Value="Prepend">
                                        <Setter Property="FrameworkElement.Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </CheckBox.Style>
                    </CheckBox>
                </StackPanel>
            </StackPanel>
        </Grid>

        <Grid Grid.Row="2" Grid.ColumnSpan="2">
            <ScrollViewer>
                <DataGrid Name="MyDataGrid" 
                          IsEnabled="{Binding Path=Files.Count}" 
                          ItemsSource="{Binding Files, UpdateSourceTrigger=PropertyChanged}" 
                          SelectedIndex="{Binding SelectedFile}"
                          AutoGenerateColumns="False" ColumnWidth="250" IsReadOnly="True" SelectionMode="Single">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="File Name" Binding="{Binding Path=FileName}" Width="*" />
                        <DataGridTextColumn Header="New File Name" Binding="{Binding Path=NewFileName}" Width="*" />
                    </DataGrid.Columns>
                </DataGrid>
            </ScrollViewer>
        </Grid>
    </Grid>
</Window>
